using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Authorization;
using UniversalAdmin.Application.Commands;
using UniversalAdmin.Application.Dto;
using UniversalAdmin.Application.Services;
using UniversalAdmin.Api.Filters;

[ApiController]
[Route("api/roles/{roleId}/menus")]
[Authorize]
public class RoleMenuMappingsController : ControllerBase
{
    private readonly IAppRoleMenuServices _service;
    public RoleMenuMappingsController(IAppRoleMenuServices service) { _service = service; }

    [HttpPost]
    [RequirePermission("role.manage")] // 需要管理角色权限
    public async Task<ApiResult> AssignMenus(Guid roleId, [FromBody] AssignRoleMenusDto dto)
    {
        dto.RoleId = roleId;
        return await _service.AssignMenusAsync(dto);
    }

    [HttpGet]
    [RequirePermission("role.view")] // 需要查看角色权限
    public async Task<ApiResult<IEnumerable<string>>> GetRoleMenus(Guid roleId)
    {
        return await _service.GetRoleMenusAsync(roleId);
    }

    [HttpDelete("{menuId}")]
    [RequirePermission("role.manage")] // 需要管理角色权限
    public async Task<ApiResult> RemoveRoleMenu(Guid roleId, Guid menuId)
    {
        return await _service.RemoveRoleMenuAsync(roleId, menuId);
    }
} 